home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
diskmags
/
0022-3.564
/
dmg-3451
/
data
/
bigsp.dat
< prev
next >
Wrap
Text File
|
1987-04-21
|
6KB
|
218 lines
Big sprite routine.
Written By Wheee the fibble.
Well, here is my nice big sprite routine. It uses screen
copy rather than the sprite command since the sprite command is
completely crap... Anyway, on with the listing...
50 mode 0 : key off : hide : flash off : click off : auto back off
: update off : curs off
This just sets up the screen and turns everything like the
cursor off.
60 fill logic+32000 to logic+32032,0 : get palette (logic)
This makes the palette black (quickly).
90 dim XY(360,1)
This is the array to hold the sprites movement pattern.
100 for T=0 to 360
Do all 360 degrees.
110 XY(T,0)=sin(rad(T*3))*cos(rad(T*4))*90+90
Calculates the X co-ordinate of the sinus wave. Sinus waves
are calculated by mutiplying various combination of SIN and COS
together.
120 XY(T,1)=cos(rad(T*3))*sin(rad(T*5))*35+35
Calculate the Y co-ordinate. I always use ,0 for the X and
,1 for the Y co-ordinate.
130 next T
Do the loop.
140 dim MARKER(7)
Used to hold the position through the memory bank of each
sprite image. I only use 8 here instead of 16 to save memory.
150 reserve as work 12,140000
Memory bank to hold the sprite image.
160 fill start(12) to start(12)+length(12),0
Clear it.
170 TT$="WTF"
The text that will be used as the sprite.
180 home : pen 1 : print TT$
Dump to the screen.
250 cls back
Clear the background screen as STOS always prints text there
too.
260 zoom physic,0,0,len(TT$)*8-1,7 to back,12,7,101,120
Zoom the text up.
270 for T=0 to 7
Do 8 images (0-7 is 8 images).
280 MARKER(T)=T*16384
This is the position of the sprite inside the memory bank.
290 screen copy back,0,0,128,128 to start(12)+MARKER(T),0,0
Copy the zoomed text to the correct place in the bank.
300 screen copy back,-2,0,318,128 to back,0,0
Scroll the screen right by 2 pixels.
310 next T
Do it for the 8 images.
320 XPS=0 : YPS=0
Used as markers to hold the position of the sprite through
the sinus wave.
330 cls physic : cls back : cls logic
Clear all of the screens.
340 palette 0,$777
Set the palette.
350 wait vbl
Wait for the next vbl as PALETTE only updates the palette then.
360 logic=back
Set up screen swap.
400 repeat
Start of the main loop.
410 SPN=(XY(XPS,0) mod 16)/2
This calculates number of the image to use. MOD gives you
the remainder of the devision (0-15) and then devides it by 2 as
I've only stored 8 images. If you imagine that the sprite is at
co-ordinates 166,100 then 166 mod 16 would give you what's
left after 166 is devided by 16, 6. Devide by two and you get 3,
so we want the 3rd sprite image in the memory bank!
420 XCRD=XY(XPS,0)/16*16
This calcualtes the nearset multiple of 16 to the left of
the sprite co-ordinate.
430 YCRD=XY(YPS,1)
Read the Y co-ordinate. A bit unneccesary, but what the hell.
440 XPS=XPS mod 360+1
This will increase XPS by one and wrap it back to 1 when it
reaches 360. It's much the same as XPS = XPS + 1 : IF XPS > 360
THEN XPS = 1 but a big faster.
450 YPS=YPS mod 360+1
Do the same for the YPS.
460 screen copy start(12)+MARKER(SPN),0,0,128,127 to logic,XCRD,YCRD
Copy the sprite to the screen. This copys the image found at
the start of bank 12 plus the value of MARKER(SPN) to the
nearest mutilple of 16 on logic.
470 screen swap
Swap the address of logic and physic.
490 wait vbl
Wait for the vbl.
500 until inkey$=" "
Until you press space.
510 fade 3 : for T=1 to 30 : wait vbl : next T
Fade out.
520 end
A bit too complicated to go into here...
Well, this may seem a bit complicated, but considering that
the 128x128 sprite takes up only about 50% processor time it's
surely worth it...
In case you don't quite see how it works I'll give a brief
account of the principle involved.
The technique itself is called "pre-shifting". Say for
example you wanted to display a sprite at co-ordinates 166,100.
With the sprite comand you'd just put in SPRITE 1,166,100,1.
But this is fantastically slow. As the ST's screen is made up in
multiples of 8 bytes (or 16 pixels) STOS has to shift your sprite's
image along by 6 pixels and the copy it to the nearest mutiple of
16. As you can imagine, this takes some time (especially when it
has benn programmed by Francois...). So then, instead of getting
STOS to shift the sprite along by 6 pixels we can do it ourselves
and so we don't need to use Francois' crap sprite routine. So,
now we can simply copy the 6th image (scrolled 6 pixels right) to
160,100 and it will appear to be at 166,100! Great! Unfortunatly
it does take up rather a lot of memory to hold 16 images and so it's
quite usual to hold only 8, each one scrolled 2 pixels to the right
rather than one.
Well, do you get it? I doubt it after my rather bad explanation,
but never mind - it'll all look different in the morning...
By the way, have a read of my doc on hertz (if it's printed)
and then put a raster in for this routine for a 64x64 sprite. Then
try it using the normal STOS sprite method to see a rather amazing
difference!
If you're intrested, this routine was taken from a disk of STOS
source that A Clockwork Orange (of Better Than Life fame) and myself
are putting together. If you want to know more give me a call
( phone (0389 648240 and ask for Billy) and I'll let you know more
about it. It should be on general release quite soon, so watch out
for it... It will give away many, many tricks used in Better than
life (full screen horizontal 64 plane parallax background taking up
about 10% processor time?? No problem...). Anyway, enough plugging
(I always feel guilty about it).
Bye then...
See you tommorow...
note from edior: These sprites may be big, but they're not as big
as the sprites sighted off the coast of western Spain in 1324 by
Hugo 'Harry' McHammish.